﻿using Ldt.DataEngine.DataFlowParse.Model;
using LdtDataEngin.ModuleDetail.BaseModule;
using LdtDataEngin.ModuleDetail.BaseModule.PersonnelBase;
using LdtJudge.DataEngine.DataBaseStores;
using LdtJudge.DataEngine.Model.Personnel;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Xml;

namespace LdtDataEngin.ModuleDetail.PersonDialogExtr
{
    public class PersonDialogExtrXml : IXmlInterface
    {
        // 上下文
        private DataContext _dataContext;

        public PersonDialogExtrXml(DataContext dataContext)

        {
            _dataContext = dataContext;
        }

        /// <summary>
        /// 提取人员对话信息
        /// </summary>
        /// <param name="configStateModel">步骤实体</param>
        /// <param name="ModelName">模块名称</param>
        /// <returns></returns>
        public DataContext Extract(ConfigModel configModel, string ModelName, XmlDocument configDetail)
        {
            if (configModel.ConfigContent != null)
            {
                XmlDocument detailDoc = new XmlDocument();
                detailDoc.LoadXml(configModel.ConfigContent);
                List<ParagraphAnalysisFactListItem> paragraphsList = XmlReadParagrap(detailDoc);
                _dataContext.DataLayerSys.paragraphAnalysisFactListItems = paragraphsList;
                ElementExtractBase elementExtractBase = new ElementExtractBase() { dataContext = _dataContext };
                elementExtractBase.LoadPersonnelInformation();
                elementExtractBase.ParesElement(paragraphsList);
                elementExtractBase.PersonSave();
                _dataContext.InteractiveShow.LogShow("人员对话获取结果:" + JsonConvert.SerializeObject(_dataContext.DataLayerAns.SpokeTextDialogue));
            }
            return _dataContext;
        }

        /// <summary>
        /// 加载人员信息段落实体
        /// </summary>
        /// <param name="xmlDocument">人员段落配置</param>
        /// <returns></returns>
        public List<ParagraphAnalysisFactListItem> XmlReadParagrap(XmlDocument xmlDocument)
        {
            XmlNodeList xmlNodeList = xmlDocument.SelectNodes("ParagraphAnalysisFactConfig/*");
            List<ParagraphAnalysisFactListItem> paragraphAnalysesList = new List<ParagraphAnalysisFactListItem>();

            foreach (XmlNode paragrnode in xmlNodeList)
            {
                if (paragrnode.Name == "ParagraphAnalysisFactList")
                {
                    ParagraphAnalysisFactListItem paragraphAnalysisFactListItem = new ParagraphAnalysisFactListItem();
                    foreach (XmlNode xmlattice in paragrnode.ChildNodes)
                    {
                        switch (xmlattice.Name)
                        {
                            case "Code_Name":
                                paragraphAnalysisFactListItem.Code_Name = xmlattice.InnerText;
                                break;
                            case "Code_Ch_Name":
                                paragraphAnalysisFactListItem.Code_Ch_Name = xmlattice.InnerText;
                                break;
                            case "SpeekPersonID":
                                paragraphAnalysisFactListItem.SpeekPersonID = xmlattice.InnerText;
                                break;
                            case "IsAnalysisTalk":
                                paragraphAnalysisFactListItem.IsAnalysisTalk = xmlattice.InnerText;
                                break;
                            case "AnanlysisCode":
                                paragraphAnalysisFactListItem.AnanlysisCode = xmlattice.InnerText;
                                break;
                            case "Inquirer":
                                paragraphAnalysisFactListItem.Inquirer = xmlattice.InnerText;
                                break;
                            case "Agent":
                                paragraphAnalysisFactListItem.Agent = xmlattice.InnerText;
                                break;
                            case "RegularCode":
                                paragraphAnalysisFactListItem.RegularCode = xmlattice.InnerText;
                                break;
                            default:
                                break;
                        }
                    }
                    paragraphAnalysesList.Add(paragraphAnalysisFactListItem);
                }
            }

            return paragraphAnalysesList;
        }
    }
}
